<?php
class rooms{
    public $table="mdkeji_chatfree_rooms";
    public $module="mdkeji_chatfree_";

    public function __construct(){

    }
    public function __destruct(){

    }
    public function getRoomidWithAddress($roomAddress){
        $roomid=pdo_getcolumn($this->table,array('roomAddress'=>$roomAddress),'room_id');
        return $roomid;
    }
    public function getRoomWithId($id,$field=array()){
        $room=pdo_get($this->table,array('room_id'=>$id),$field);
        return $room;
    }
    public function getRoomWithCode($Code,$field=array()){
        $room=pdo_get($this->table,array('room_code'=>$Code),$field);
        return $room;
    }
    public function getRoomsInfo($field){
        $roomsInfo=pdo_getall($this->table,array(),$field);
        return $roomsInfo;
    }
    public function getMessage($room_id,$msgtimes,$much){
        // array(':mt'=>$msgtimes,':much'=>$much)这里的数字会被变成单引号的字符串
        $msg30=pdo_fetchall("select * from (select * from  ".tablename($this->module.$room_id)." order by Id desc limit ".$msgtimes.",".$much.") as mmm order by Id");
        return $msg30;
    }
    public function pullDownRefresh($msgsTopId,$room_id,$much){
        // array(':msgsTopId'=>$msgsTopId,':mt'=>0,':much'=>$much)这里的数字会被变成单引号的字符串
        /* 区分是否私聊 */
        if($room_id=="room_private"){
            $saytoone=pdo_getcolumn($this->module.$room_id,array('Id'=>$msgsTopId),'saytoone');            
            $msg30=pdo_fetchall("select * from (select * from  ".tablename($this->module.$room_id)." where Id < ".$msgsTopId." and saytoone = '".$saytoone."' order by Id desc limit 0,".$much.") as mmm order by Id");
        }else{
            $msg30=pdo_fetchall("select * from (select * from  ".tablename($this->module.$room_id)." where Id < ".$msgsTopId." order by Id desc limit 0,".$much.") as mmm order by Id");
        }
        return $msg30;
      
    }
    public function updateRoomsSet($data,$con=array()){
        $res=pdo_update($this->table,$data,$con);
        return $res;
    }
    public function insertRoom($data){
        $res=pdo_insert($this->table,$data);
        if(!empty($res)){
            return pdo_insertid();
        }else{
            return null;
        }
    }
    public function insertRoom_1($data){
        $res=pdo_insert($this->module.'room_1',$data);
        if(!empty($res)){
            return pdo_insertid();
        }else{
            return null;
        }
    }
    public function getMessageRoom_1($msgtime){
        $msg=pdo_fetchall("select * from  ".tablename($this->module.'room_1')." where sendtime>:sendtime order by Id",array(":sendtime"=>$msgtime));
        return $msg;
    }


}